import { Tile_Interface } from "./tile_interface";
import { Tile_Bank } from "./tile_bank";
import { Adapter } from "../adapter/adapter";
import { BitMath } from "../math/math";
export namespace Tile_Element
{
    
    export class RenderTile implements Tile_Interface.IDrawElement_WithSize
    {
        constructor(bank: Tile_Bank.Bank, tileID: number, tex: Adapter.ITexture, srcrect: BitMath.Rect)
        {
            this.bank = bank;
            this.tileID = tileID;
            this.tex = tex;
            this.srcrect = srcrect;
        }
        public get width(): number
        {
            return this.srcrect.w;
        }
        public get height(): number
        {
            return this.srcrect.h;
        }
        public bank: Tile_Bank.Bank;
        public tileID: number;
        public tex: Adapter.ITexture;
        public srcrect: BitMath.Rect;
        Draw(render: Adapter.IRenderAdapter, x: number, y: number, multiColorIndex: number): void
        {
            render.Draw(this.tex, this.srcrect, x, y, multiColorIndex);
        }
        DrawScale(render: Adapter.IRenderAdapter, dest: BitMath.Rect, multiColorIndex: number): void
        {
            render.DrawScale(this.tex, this.srcrect, dest, multiColorIndex);
        }
    }
    export class WriteableTile implements Tile_Interface.IDrawElement_WithSize
    {
        // SDL.SDL_Color[] palette;
        constructor(render: Adapter.IRenderAdapter, palette: BitMath.OutPalette, width: number, height: number)
        {
            this.tex = render.CreateWriteableTexture(palette, width, height);
            this.srcrect = new BitMath.Rect();
            this.srcrect.x = 0;
            this.srcrect.y = 0;
            this.srcrect.w = width;
            this.srcrect.h = height;
        }
        tex: Adapter.ITexture_Writeable;
        srcrect: BitMath.Rect;
        Close(): void
        {
            this.tex.Close();
        }
        public get width(): number
        {
            return this.srcrect.w;
        }
        public get height(): number
        {
            return this.srcrect.h;
        }
        Draw(render: Adapter.IRenderAdapter, x: number, y: number, multiColorIndex: number): void
        {
            render.Draw(this.tex, this.srcrect, x, y, multiColorIndex);
        }
        DrawScale(render: Adapter.IRenderAdapter, dest: BitMath.Rect, multiColorIndex: number): void
        {
            render.DrawScale(this.tex, this.srcrect, dest, multiColorIndex);
        }
    }

}